<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<section class="wrapper">
    <div class="row">
        <div class="col-lg-12">
            <section class="panel">
                <header class="panel-heading">
                    广告公司
                    <button type="button" class="btn btn-info pull-right"
                            onclick="oceanModal.openDefault('dept/adCompany/item')">新增广告公司
                    </button>
                </header>
                <div class="col-lg-12">
                    <%--<div class="search">--%>
                    <form id="adCompany_select_form">
                        <label style="color: #737B83;">名称:</label>
                        <input type="text" class="txt" id="name1" name="name1" placeholder="名称的关键字"
                               style="margin-top: 10px;" required/>&nbsp;&nbsp;&nbsp;
                        <label style="color: #737B83;">地址:</label>
                        <input type="text" class="txt" id="address1" name="address1" placeholder="地址的关键字"
                               style="margin-top: 10px;" required/>&nbsp;&nbsp;&nbsp;
                        <label style="color: #737B83;">联系人:</label>
                        <input type="text" class="txt" id="contactName1" name="contactName1" placeholder="联系人的关键字"
                               style="margin-top: 10px;" required/>&nbsp;&nbsp;&nbsp;
                        <label style="color: #737B83;">联系手机:</label>
                        <input type="text" class="txt" id="contact1" name="contact1" placeholder="联系手机的关键字"
                               style="margin-top: 10px;" required/>&nbsp;&nbsp;&nbsp;
                        <input type="button" id="search" class="btn" onclick="adCompanyPage.select()" value="搜索"/>
                        <input type="reset" id="return" class="btn" onclick="load()" value="重置"/>
                    </form>
                    <%--</div>--%>
                </div>
                <div class="panel-body">
                    <table class="table table-striped table-bordered sortable">
                        <thead>
                        <tr>
                            <th>名称</th>
                            <th>地址</th>
                            <th>营业执照编号</th>
                            <th>联系人</th>
                            <th>联系手机</th>
                            <th>座机</th>
                            <th>邮箱</th>
                            <th>邮政编码</th>
                            <th>描述</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="adCompany-list-body">

                        </tbody>
                    </table>
                    <div class="text-center">
                        <ul class="pagination">

                        </ul>
                    </div>
                </div>
            </section>
        </div>
    </div>
</section>

<script type="text/template" id="adCompany-list-template">
    <@ _.each(items, function (item) { @>
    <tr>
        <td><@= item.name @></td>
        <td><@= item.address @></td>
        <td><@= item.licence @></td>
        <td><@= item.contactName @></td>
        <td><@= item.contact @></td>
        <td><@= item.mobile @></td>
        <td><@= item.email @></td>
        <td><@= item.zipcode @></td>
        <td>
            <button class="btn btn-primary btn-xs"
                    onclick="oceanModal.openDefault('dept/adCompany/item?id=<@= item.id @>')">
                <i class="icon-pencil"></i>
            </button>
            <button class="btn btn-danger btn-xs"
                    onclick="confirmDialog.drop('<@= item.id @>','<@= item.name @>', 'com.ocean.billboard.entity.AdCompany')">
                <i class="icon-trash "></i>
            </button>

            <button class="btn btn-success btn-xs"
                    onclick="oceanModal.openDefault('dept/adCompany/details?id=<@= item.id @>')">详情
            </button>
        </td>
    </tr>
    <@ }); @>
</script>
<script type="text/template" id="adCompany-page-template">
    <@ for(var index=1;index<=totalPages;index++) { @>
    <@ if(number==index-1) {@>
    <li class="active"><a href="javascript:void(0)" data-index="<@=index @>"><@=index @></a></li>
    <@ } else { @>
    <li><a href="javascript:void(0)" data-index="<@=index @>"><@=index @></a></li>
    <@ }} @>
</script>
<script type="application/javascript">
    function load(page) {
        if (page == null) {
            page = 1;
        }
        WaitingDialog.show();
        $.post("resources/adCompany/list", {page: page}, function (data) {
            console.log(data);
            WaitingDialog.dismiss();
            if (data == null) {
                return;
            }
            var tmpl = _.template($('#adCompany-list-template').html());
            $('#adCompany-list-body').html(tmpl({items: data.content}));

            var tmpl_page = _.template($('#adCompany-page-template').html());
            $('.pagination').html(tmpl_page({totalPages: data.totalPages, number: data.number}));

            $('.pagination a').click(function () {
                load($(this).data("index"));
            });
        });
    }
    load();
    var adCompanyPage = {
        select: function (page) {
            if (page == null) {
                page = 1;
            }
            var name, address, contactName, contact;
            name = $('#name1').val();
            address = $('#address1').val();
            contactName = $('#contactName1').val();
            contact = $('#contact1').val();
            WaitingDialog.show();
            $.post("resources/adCompany/select", {
                name: name,
                address: address,
                contactName: contactName,
                contactPhone: contact,
                page: page
            }, function (data) {
                console.log(data);
                WaitingDialog.dismiss();
                if (data == null) {
                    return;
                }
                var tmpl = _.template($('#adCompany-list-template').html());
                $('#adCompany-list-body').html(tmpl({items: data.content}));

                var tmpl_page = _.template($('#adCompany-page-template').html());
                $('.pagination').html(tmpl_page({totalPages: data.totalPages, number: data.number}));

                $('.pagination a').click(function () {
                    adCompanyPage.select($(this).data("index"));
                });
            });
        }
    }
</script>
